import java.util.Scanner;

/**
 * 多用户版本的ATM
 * @author BDK-THINKPAD
 *
 */
public class ATM03 {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		// 定义系统提供的账号、密码和余额
//		int [] sysAccount = {111111,222222,333333,444444,555555};
//		int [] sysPwd = {123123,321321,13579,24680,88888};
//		double [] sysBlance = {1000,2000,3000,4000,5000};
		String [][] systemInfos = {
				{"111111","123123","1000.0"},
				{"222222","321321","2000.0"},
				{"333333","13579","3000.0"},
				{"444444","24680","4000.0"},
				{"555555","888888","5000.0"}
		};
		for (int i = 0; i < 3; i++) {
			System.out.println("请输入账号：");
			String account = sc.next();
			System.out.println("请输入密码：");
			String pwd = sc.next();
			boolean flag = false;
			// 登录成功的数组下标
			int index = 0;
			// 循环验证输入的账号和密码是否相等
			for(int j = 0;j < systemInfos.length;j++) {
				if(systemInfos[j][0].equals(account) && systemInfos[j][1].equals(pwd)) {
					System.out.println("登录成功");
					flag = true;
					index = j;
					break;
				}
			}
			

			if (flag) {
				for (;;) {
					System.out.println("请选择：1-存款 2-取款 3-查询 4-退出 5-注销");
					int input = sc.nextInt();

					if (input == 1) {
						// 存款操作
						System.out.println("请输入存的金额：");
						double blance = sc.nextDouble();
						systemInfos[index][2] = Double.parseDouble(systemInfos[index][2]) + blance + "";
						System.out.println("当前余额：" + systemInfos[index][2]);
					} else if (input == 2) {
						// 取款操作
						System.out.println("请输入取得金额：");
						double blance = sc.nextDouble();
						double sysBlance = Double.parseDouble(systemInfos[index][2]);
						if (blance > sysBlance) {
							System.out.println("余额不足！");
						} else {
							systemInfos[index][2] = sysBlance - blance + "";
							System.out.println("当前余额：" + systemInfos[index][2]);
						}

					} else if (input == 3) {
						// 查询操作
						System.out.println("当前余额：" + systemInfos[index][2]);
					} else if (input == 4) {
						System.out.println("谢谢使用！");
						// 程序结束的方法
						System.exit(0);
					} else if(input == 5){
						i = -1;
						break;
					} else {
						System.out.println("输入有误");
					}
				}
				
			} else {
				if (i < 2) {
					System.out.println("账号或密码输入有误，还剩" + (2 - i) + "次！");
				} else {
					System.out.println("你的卡已被吞掉，再见！");
				}

			}
			
		}

	}

}
